package com.gyx.lottery.service.activitystatus.operator;

import com.gyx.lottery.dao.dataobject.ActivityPrizeDO;
import com.gyx.lottery.dao.mapper.ActivityPrizeMapper;
import com.gyx.lottery.service.dto.ConvertActivityStatusDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PrizeOperator extends  AbstractActivityOperator{
    @Autowired
    ActivityPrizeMapper activityPrizeMapper;
    @Override
    public Integer sequence() {
        return 1;
    }

    @Override
    public Boolean needCovert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        Long activityId = convertActivityStatusDTO.getActivityId();
        Long prizeId = convertActivityStatusDTO.getPrizeId();
        if(activityId == null || prizeId == null){
            return  false;
        }
        ActivityPrizeDO activityPrizeDO = activityPrizeMapper.
                selectByIdAndPrizeId(activityId, prizeId);
        if(activityPrizeDO == null || activityPrizeDO.getStatus().equalsIgnoreCase(
                convertActivityStatusDTO.getTargetPrizeStatus().name())){
            return false;
        }

        return true;
    }

    @Override
    public Boolean covert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        try{
            activityPrizeMapper.updatePrizeStatus(
                    convertActivityStatusDTO.getActivityId(),
                    convertActivityStatusDTO.getPrizeId(),
                    convertActivityStatusDTO.getTargetPrizeStatus().name());
            return  true;
        }catch (Exception e){
            return false;
        }
    }
}
